package com.example.backend.common.validator;

import com.example.backend.common.api.ResultCode;
import com.example.backend.common.exception.BusinessException;
import org.springframework.stereotype.Component;

@Component
public class PasswordValidator {
    
    private static final String PATTERN = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,16}$";
    
    /**
     * 校验密码强度
     * 1. 长度6-16位
     * 2. 必须包含大小写字母和数字
     */
    public void validate(String password) {
        if (!password.matches(PATTERN)) {
            throw new BusinessException(ResultCode.INVALID_PASSWORD);
        }
    }
} 